//
//  CustomView.m
//  RunLoopDemo
//
//  Created by zhangjikuan on 2020/11/25.
//  Copyright © 2020 hsgd. All rights reserved.
//

#import "CustomView.h"
#import <UIKit/UIStackView.h>

@implementation CustomView

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    // 1.判断自己能否接收触摸事件
    if (self.userInteractionEnabled == NO || self.hidden == YES || self.alpha <= 0.01) return nil;
    // 2.判断触摸点在不在自己范围内
    if (![self pointInside:point withEvent:event]) return nil;
    // 3.从后往前遍历自己的子控件，看是否有子控件更适合响应此事件
    int count = self.subviews.count;
    for (int i = count - 1; i >= 0; i--) {
        UIView *childView = self.subviews[i];
        CGPoint childPoint = [self convertPoint:point toView:childView];
        UIView *fitView = [childView hitTest:childPoint withEvent:event];
        if (fitView) {
            return fitView;
        }
    }
    // 没有找到比自己更合适的view
    return self;
    
    int a = 0, b = 2 ;

    int ret = a ^= b;
    
    
    
}

- (void)drawRect:(CGRect)rect {
    
}

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {
    
}

@end
